package com.yuhs.zixing.study.multithread.mashibing.t002lock.l002;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * Function: volatile
 * 保证可见性 禁止指令重排序
 *
 * @Author yuhongsheng
 * @Date: 2023-12-23 19:59:42
 */
@Slf4j
public class Lock002Volatile001 {

    boolean running = true;

    public void m() {
        log.atInfo().log("方法开始");
        while (running) {

        }
        log.atInfo().log("方法结束");
    }

    @SneakyThrows
    public static void main(String[] args) {

        Lock002Volatile001 volatile001 = new Lock002Volatile001();
        new Thread(volatile001::m).start();
        TimeUnit.SECONDS.sleep(1);
        volatile001.running=false;

    }


}
